<?php
/**
 * Created by PhpStorm.
 * User: LiuTao
 * Date: 2018/11/12
 * Time: 17:50
 */

$len = 1024;
$flags = 0;
$from = "";
$port = 14446;
$group_params = array(
    "group" => "228.5.6.7",
    "interface" => 0
);
$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
socket_bind($socket, '0.0.0.0', $port);
socket_set_option($socket, IPPROTO_IP, MCAST_JOIN_GROUP, $group_params);

while (true) {
    echo "Waiting for data ... \n";
    //Receive
    socket_recvfrom($socket, $recvStr, $len, $flags, $from, $port);
    echo "Received" . $recvStr . " from " . $from."\n";
}

socket_close($socket);